
package datastructure.tree;

/**
 * Symmetrical tree is as follows
 *
     1
   /   \
  2     2
 / \   / \
4   3 3   4
 *
 *
 *
 * @author Lei Zhang
 */
public class IsBinaryTreeSymmetrical {


 public static Boolean isBinaryTreeSymmetrical(TreeNode left, TreeNode right) {
  if (left == null || right == null) return left == null && right == null;
  return left.value == right.value && 
         isBinaryTreeSymmetrical(left.left, right.right) &&
         isBinaryTreeSymmetrical(left.right, right.left);
}

 public static Boolean isBinaryTreeSymmetrical_1(TreeNode root) {

    // inorder travesal to create a string, check the string.
    return false;

 }


 public static void main(String args[]) {

    TreeNode n1 = new TreeNode(1);
    TreeNode n2 = new TreeNode(2);
    TreeNode n3 = new TreeNode(3);
    TreeNode n4 = new TreeNode(4);
    TreeNode n5 = new TreeNode(5);
    TreeNode n6 = new TreeNode(6);

    n5.left = n2;
    n5.right = n6;

    n2.left = n1;
    n2.right = n4;

    n4.left = n3;

    System.out.println(IsBinaryTreeSymmetrical.isBinaryTreeSymmetrical(n5.left,
        n5.right));
  }

}
